package linked;

public class MergeTwoLists {
    public static void main(String[] args) {
        ListNode l2 = new ListNode(2);
        ListNode l3 = new ListNode(3);
        ListNode l4 = new ListNode(4);
        ListNode l5 = new ListNode(1);
        ListNode l6 = new ListNode(4);
        ListNode input1 = new ListNode(1);
        input1.next = l2;
        input1.next.next = l4;
        ListNode input2 = new ListNode(1);
        input2.next = l3;
        input2.next.next = l6;
        mergeTwoLists(input1, input2);

    }

    public static ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode head = new ListNode();
        ListNode curr = head;
        while(list1!=null&&list2!=null){
            if(list1.val<list2.val){
                curr.next = new ListNode(list1.val);
                list1 = list1.next;
            }else{
                curr.next = new ListNode(list2.val);
                list2 = list2.next;
            }
            curr = curr.next;
        }
        curr.next = list1!=null?list1:list2;
        return head.next;
    }


}
